package cn.bytecollege.user.controller;

import cn.bytecollege.common.entity.OrderDetail;
import cn.bytecollege.user.service.OrderDetailService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "OrderDetailUpdateController",value = "/user/orderDetailUpdate")
public class OrderDetailUpdateController extends HttpServlet {
    OrderDetailService orderDetailService=null;
    public OrderDetailUpdateController(){
        orderDetailService=new OrderDetailService();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     String update=request.getParameter("update");
     String orderDetailId=request.getParameter("orderdetailid");
     OrderDetail orderDetail=orderDetailService.findById(Integer.valueOf(orderDetailId));
     if(update.equals("0")){           //0为增加,1为减少
         Integer ProductNumber=orderDetail.getProductNumber();
         ProductNumber-=1;
         orderDetail.setProductNumber(ProductNumber);
         orderDetailService.update(orderDetail);
     } else if(update.equals("1")){
         Integer ProductNumber=orderDetail.getProductNumber();
         ProductNumber+=1;
         orderDetail.setProductNumber(ProductNumber);
         orderDetailService.update(orderDetail);
     }
     response.sendRedirect("/user/orderlist");


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     doPost(request, response);
    }
}
